package git.bankview.wl.report;

import java.util.*;
import java.text.*;
import java.io.*;

import laya.semi.process.*;

import git.bankview.sl.db.*;
import git.bankview.sl.report.ReportCommon;

import org.apache.log4j.Logger;

public class AccessoriesFilter
	implements IGenericClassActivity
{
	private static Logger log = Logger.getLogger(AccessoriesFilter.class);

	public void execute(IProcessContext oCtx)
		throws Exception
	{
		String[] params = oCtx.getActivityParameter().split(":");
		
		String oTransid = (String)oCtx.getField("transid");
		String[] vAccessoryFileNames = (String[])oCtx.getField(params[0]);
		
		if (null != vAccessoryFileNames)
		{
			String[] vSelectedAccessories = (String[])oCtx.getField(params[1]);
			
			File dir = new File(ReportCommon.JASPER_DIR + oTransid);

			File[] v = dir.listFiles();
			
			for (int i = 0; i < v.length; ++i)
			{
				String destName = v[i].getName();
				if (destName.equalsIgnoreCase(params[2]))
					continue;
				
				boolean bDelete = true;
				for (int j = 0; null != vSelectedAccessories && j < vSelectedAccessories.length; ++j)
				{
					if (destName.equalsIgnoreCase(vAccessoryFileNames[Integer.parseInt(vSelectedAccessories[j])]))
					{
						bDelete = false;
						break;
					}
				}
				
				if (bDelete)
					v[i].delete();
			}
		}
	}
}
